package com.s7175.kor.model;

import java.util.ArrayList;
import java.util.Collection;

public class Component extends ModelMaster{

	private String name;
	private Component parent;
	private ArrayList<Component> components = new ArrayList<Component>();
	private ArrayList<Attribute> attributes = new ArrayList<Attribute>();
	private ArrayList<Server> servers = new ArrayList<Server>();

	public Component(String name) {
		this.setName(name);
	}

	public String toString() {
		return "Component[name=\"" + name + "\", servers: " + servers.size()
				+ "]";
	}

	public Component(String name, Component oParent) {
		this.setName(name);
		this.parent = oParent;
		oParent.getChildList().add(this);
	}

	public void addChild(Component oChild) {
		this.components.add(oChild);
	}

	public boolean hasChild(Component child) {
		return components.contains(child);
	}

	public boolean removeChild(Component child) {
		return components.remove(child);
	}

	public boolean addAttribute(Attribute oAttribute) {
		return this.attributes.add(oAttribute);
	}

	public ArrayList<Attribute> getAttributes() {
		return this.attributes;
	}

	public Component getChild(int index) {
		return this.components.get(index);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Component getParent() {
		return parent;
	}

	public void setParent(Component sParent) {
		this.parent = sParent;
	}

	public Collection<Component> getComponents() {
		return this.components;
	}

	public void setComponents(Collection<Component> components) {
		this.components.clear();
		this.components.addAll(components);
	}

	public ArrayList<Component> getChildList() {
		return components;
	}

	public void setChildList(ArrayList<Component> oChildList) {
		this.components = oChildList;
	}

	public ArrayList<Server> getServers() {
		return servers;
	}

	public boolean addServer(Server s) {
		return this.servers.add(s);
	}

	public boolean removeServer(Server server) {
		return this.servers.remove(server);
	}

}
